package com.servlet; /**
 * @author wzm
 * @create 2023-03-16 14:47
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        if ("zs".equals(username) && "123456".equals(password)) {
            //登录成功
            request.getSession().setAttribute("loginUser", username);
            request.getRequestDispatcher("/index.jsp").forward(request,response);
        }else{
            //失败
            request.getSession().setAttribute("msg", "登录失败");
            request.getRequestDispatcher("/login.jsp").forward(request,response);
        }

    }
}
